
const executablePath = 'C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe';

const puppeteer = require('puppeteer');
const { v4: uuidv4 } = require('uuid');
const os = require('os');


let renderHtml = `http://localhost/index.html`


exports.getStructurePic = async(req, res)=> {  
  const id = uuidv4();

  const struturePath = req.query.struturePath;

  const browser = await puppeteer.launch({
    executablePath, 
    headless: true,
    args: [
      "--disable-web-security",                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         
      "--enable-webgl",
      "--disable-dev-shm-usage",
      "--disable-setuid-sandbox",
      "--no-sandbox"
    ]
  });

  const page = await browser.newPage();

  await page.setViewport({
    width: 450,
    height: 450,
	
  });

   

  await page.goto(`${renderHtml}?cifFile=${struturePath}`);
  
  startShot(page, browser, res, struturePath, id);
}

async function startShot(page, browser, res, struturePath, id) {
	
//共享磁盘的路径
  
	
  await page.screenshot({
    path:  '/sss',
	omitBackground:true
  });

  await browser.close();

  res.json({
    code: '200',
    path: 'http://localhost/sss'
  })
}

